package alquilers;

import java.util.HashMap;
import java.util.Scanner;
import java.util.Map;
import java.util.ArrayList;

public class AlquilersTester {
	


	public static void main(String[] argv) throws Exception {
		alquilers.ws.AlquilersService service = new alquilers.ws.AlquilersServiceLocator();
		alquilers.ws.Alquilers alquilers = service.getalquilers();
		HashMap<String, Double> priceInfo = new HashMap<String, Double>();
		Scanner in= new Scanner(System.in);
		
		
		
		
		
		if (argv.length == 1) {
			String command = argv[0];
			if (command.equals("afegir")) {
				HashMap<String, String> values = new HashMap<String, String>();
				String model,motor,quantitat,dies,descompte;
				System.out.println("Insereix les dades del lloguer:");

				System.out.println("Model:(Economic/Semi-Luxe/Luxe/Limusina)");
				model = in.nextLine();
				System.out.println("Motor:(Gasolina/Diesel)");
				motor = in.nextLine();
				System.out.println("Quantitat: ");
				quantitat = in.nextLine();
				System.out.println("Dies: ");
				dies = in.nextLine();
				System.out.println("Descompte: *.*");
				descompte = in.nextLine();
				System.out.println("Guardant Reserva...");

				Double price = alquilers.addEntry(model,motor,quantitat,dies,descompte);
				if (price == -1)
					System.out.println("Parametres incorrectes");
				else
					System.out.println("Preu final: " + price);
			} else if (command.equals("llistar")) {
				String username, password;
				System.out.println("Usuari: ");
				username = in.nextLine();
				System.out.println("Contrasenya: ");
				password = in.nextLine();
				System.out.println("");
				System.out.println("Llistat de transaccions:");

				String[] v= alquilers.listado(username,password);
				if (v != null) {
					for (int i = 0; i < v.length ; i+=6) {
						System.out.println("-- Model: " + v[i] + " "
								+ "Motor: " + v[i+1] + " "
								+ "Quantitat: " + v[i+2] + " "
								+ "Dies: " + v[i+3] + " "
								+ "Descompte: " + v[i+4] + " "
								+ "Preu Final: " + v[i+5]);
					}
				} else {
					System.out.println("Error: Usuari o Password incorrectes");
				}

			} else {
				System.out.println(command + " is not a valid option.");
				printUsage();
			}
		} else {
			printUsage();
		}
	}

	public static void printUsage() {
		System.out
				.println("Usage: Lloguer [option] \n on opcio es una de les seguents:");
		System.out.println("  afegir   - afegir un nou lloguer");
		System.out.println("  llistar - llista tots els lloguers en xml.");
	}

}